clc;clear;close all;warning off;
%% 生成图片的参数
%=========================  Default     ===================================
I_rows = 1140;      %行像素数
I_cols = 912;       %列像素数
A = 0.5;            %光强
B1 = 0;             %谐波
nm = 0;         %噪声均值
gamma = 1;      %非线性
pst = 0;        %倾斜相移
arguments = ["B","N","F"];
for i = 1:strlength(arguments)
   mkdir(arguments(i));
end
mkdir('595348');
F = 4;
ni = zeros(1,F);
ps = zeros(1,F);    %未知相移
%==================================三频四相===============================================
filepath = '595348/59';
Figure59 = fun_createFigure(F, A, 120/256, B1, 59, I_rows, I_cols, ni, nm, gamma, ps, pst, filepath);
filepath = '595348/53';
Figure53 = fun_createFigure(F, A, 120/256, B1, 53, I_rows, I_cols, ni, nm, gamma, ps, pst, filepath);
filepath = '595348/48';
Figure48 = fun_createFigure(F, A, 120/256, B1, 48, I_rows, I_cols, ni, nm, gamma, ps, pst, filepath);

I = zeros(I_rows,I_cols,3);
I(:,:,1) = Figure59{1,1};
I(:,:,2) = Figure59{2,1};
I(:,:,3) = Figure59{3,1};
imwrite(I,'595348/1.bmp');
I(:,:,1) = Figure59{4,1};
I(:,:,2) = Figure53{1,1};
I(:,:,3) = Figure53{2,1};
imwrite(I,'595348/2.bmp');
I(:,:,1) = Figure53{3,1};
I(:,:,2) = Figure53{4,1};
I(:,:,3) = Figure48{1,1};
imwrite(I,'595348/3.bmp');
I(:,:,1) = Figure48{2,1};
I(:,:,2) = Figure48{3,1};
I(:,:,3) = Figure48{4,1};
imwrite(I,'595348/4.bmp');

%=========================  Experiment 1   ===================================
% 实验1
%   目的：为了探究不同B值下，算法的优势程度
%   对照组数量：8组
%   对照参数：B = linspace(50, 120, 8)/256;
F = 6;              %F步相移
T = I_cols/59;             %一个周期像素数
freq = I_cols / T;  %根据周期计算频率
B = linspace(50, 120, 8)/255;
ni = zeros(1,F);
for i = 1:length(B)
    mkdir('B\',['B=',int2str(B(i)*255)]);
    filepath = ['B\','B=',int2str(B(i)*255),'\I'];
%     save([filepath,'ni.mat'],"ni");
    Figure = fun_createFigure(F, A, B(i), B1, freq, I_rows, I_cols, ni, nm, gamma, ps, pst, filepath);
%     % 将图像合成24bit位图
    I = zeros(I_rows, I_cols, ceil(F/3)*3);
    for f = 1:F
        I(:,:,f) = Figure{f,1};
    end
    for index = 1:ceil(F/3)
        startIndex = 1 + (index - 1)*3;
        endIndex = index*3;
        imwrite(I(:,:,startIndex:endIndex),[filepath,int2str(index),'.bmp']);
    end
end
%=========================  Experiment 2   ===================================
% 仿真实验2
%   目的：为了探究不同F值下，算法的优势程度
%   对照组数量：8组
%   对照参数：F = linspace(3, 10, 8);
T = 14.25;             %一个周期像素数
freq = I_cols / T;  %根据周期计算频率
B = 120/256;
F = linspace(3, 10, 8);
for i = 1:length(F)
    ps = zeros(1,F(i));    %未知相移
    ni = zeros(1,F(i));
    filepath = ['Experiment/Experiment (2)/Figure (',int2str(i),')/I'];
    Figure = fun_createFigure(F(i), A, B, B1, freq, I_rows, I_cols, ni, nm, gamma, ps, pst, filepath);
    % 将图像合成24bit位图
    I = zeros(I_rows, I_cols, ceil(F(i)/3)*3);
    for f = 1:F(i)
        I(:,:,f) = Figure{f,1};
    end
    for index = 1:ceil(F(i)/3)
        startIndex = 1 + (index - 1)*3;
        endIndex = index*3;
        imwrite(I(:,:,startIndex:endIndex),[filepath,int2str(index),'.bmp']);
    end
end
%=========================  Experiment 3   ===================================
% 仿真实验3
%   目的：为了探究不同T值下，算法的优势程度
%   对照组数量：8组
%   对照参数：T = [10 20 25 50 100 125 250 500];
F = 6;              %F步相移
B = 120/256;
ps = zeros(1,F);    %未知相移
ni = zeros(1,F);
freq = [40 45 50 55 60 65 70 75];
% T = [10 20 25 50 100 125 250 48];             %一个周期像素数
for i = 1:length(freq)
%     freq = I_cols / T(i);  %根据周期计算频率
    filepath = ['Experiment/Experiment (3)/Figure (',int2str(i),')/I'];
    save([filepath,'ni.mat'],"ni");
    fun_createFigure(F, A, B, B1, freq(i), I_rows, I_cols, ni, nm, gamma, ps, pst, filepath);
    % 将图像合成24bit位图
    I = zeros(I_rows, I_cols, ceil(F/3)*3);
    for f = 1:F
        I(:,:,f) = Figure{f,1};
    end
    for index = 1:ceil(F/3)
        startIndex = 1 + (index - 1)*3;
        endIndex = index*3;
        imwrite(I(:,:,startIndex:endIndex),[filepath,int2str(index),'.bmp']);
    end
end

